from django.db import models
from django.contrib.auth.hashers import make_password, check_password
from django.contrib.auth.models import AbstractUser


# 管理员登录账号与密码以及用于自定义用户表生成token
class ChargeAdmin(AbstractUser):
    sex_choices = (
        ('1', '男'),
        ('2', '女')
    )
    status_choices = (
        ('1', '在线'),
        ('2', '离线')
    )
    is_super_choices = (
        ('0', '普通管理员'),
        ('1', '超级管理员')
    )
    id = models.BigAutoField(primary_key=True)
    username = models.CharField(max_length=15, verbose_name='用户名', unique=True)
    password = models.CharField(max_length=15, verbose_name='密码')
    nick_name = models.CharField(max_length=5, verbose_name='管理人员名字', unique=True)
    sex = models.CharField(max_length=1, choices=sex_choices, verbose_name='性别', default='1')
    status = models.CharField(max_length=1, choices=status_choices, verbose_name='人员在线状态', default='2')
    created_time = models.DateTimeField(auto_now_add=True, verbose_name='账号创建时间')
    mobile = models.CharField(verbose_name='联系电话',max_length=15,null=True)
    is_super = models.CharField(max_length=1,choices=is_super_choices,null=True,verbose_name='管理员权限控制')
    USERNAME_FIELD = 'username'

    @property
    def is_authenticated(self):
        """
        Always return True. This is a way to tell if the user has been
        authenticated in templates.
        """
        return True

    class Meta:
        db_table = 'shop_admin'
        verbose_name = "用户账号表"
        verbose_name_plural = verbose_name


# Create your models here.

# 宠物档案管理->宠物的基本信息
class PetMessage(models.Model):
    healthy_choices = (
        (1, '健康'),
        (2, '少许疾病'),
        (3, '重大疾病'),
        (4, '残疾'),
        (5, '其他')
    )
    sex_choices = (
        (1, '公'),
        (2, '母')
    )

    vaccines_choices = (
        (1, '已接种'),
        (2, '未接种')
    )
    id = models.BigAutoField(primary_key=True)
    petname = models.CharField(max_length=100, null=True, verbose_name='宠物小名', unique=True)
    petsex = models.IntegerField(choices=sex_choices, verbose_name='宠物性别')
    petage = models.FloatField(max_length=50, verbose_name='宠物年龄')
    petcatagory = models.CharField(max_length=10, verbose_name='宠物种类', null=True)
    petkind = models.CharField(max_length=10, verbose_name='宠物品种')
    healthy = models.IntegerField(choices=healthy_choices, verbose_name='宠物健康程度')
    imagesurl = models.CharField(max_length=100, verbose_name='图片地址')
    petvaccines = models.IntegerField(choices=vaccines_choices, verbose_name='是否注射了疫苗')
    petvaccinestime = models.DateTimeField(verbose_name='上一次接种疫苗时间')
    apply_account = models.CharField(max_length=100, verbose_name='申请建档的账号', null=True)
    description = models.CharField(max_length=1000, blank=True, null=True, default='无', verbose_name='其他描述')

    def formatted_date(self):
        return self.petvaccinestime.strftime('%Y/%m/%d')

    class Meta:
        db_table = 'pet_message'


# 宠物主人信息档案
class PetOwner(models.Model):
    sex_choices = (
        (1, '男'),
        (2, '女')
    )
    id = models.AutoField(primary_key=True)
    ownername = models.CharField(unique=True, max_length=10, verbose_name='宠物主人姓名')
    ownersex = models.IntegerField(choices=sex_choices, null=True, verbose_name='宠物主人性别')
    ownerphone = models.CharField(max_length=13, null=True, unique=True, verbose_name='宠物主人联系方式')
    owneraddress = models.CharField(max_length=50, null=True, verbose_name='宠物主人住址')
    created_time = models.DateTimeField(verbose_name='顾客建档时间', null=True)
    pet = models.CharField(max_length=50, unique=True, verbose_name='该顾客所拥有的宠物名字', null=True)
    class Meta:
        db_table = 'pet_owner'


# 寄养
class FosterPet(models.Model):
    state_choices = (
        (0, '待寄养'),
        (1, '寄养中'),
        (2, '已领回'),
    )
    checkout_choices = (
        (1, '已结算'),
        (2, '未结算')
    )
    pet_foster_name = models.CharField(max_length=100, null=True,verbose_name='寄养的宠物名字')
    pet_foster_master = models.CharField(max_length=100,null=True, verbose_name='寄养宠物的账号')
    pet_foster_master_name = models.CharField(max_length=100,null=True,verbose_name='寄养宠物的主人姓名')
    pet_foster_master_phone = models.CharField(max_length=13, null=True, verbose_name='联系电话')
    pet_foster_master_IDcard = models.CharField(max_length=18, null=True, verbose_name='寄养宠物主人的身份证件')
    foster_start_time = models.DateTimeField(auto_now_add=True, verbose_name='寄养开始时间')
    foster_end_time = models.DateTimeField(null=True, verbose_name='寄养结束时间')
    foster_unit_price = models.IntegerField(null=True, verbose_name='寄养每小时的单价')
    is_state = models.IntegerField(choices=state_choices, verbose_name='寄养状态')
    is_checkout = models.IntegerField(choices=checkout_choices, verbose_name='寄养结束的结算状态')
    description = models.CharField(max_length=1000,null=True, verbose_name='对寄养的描述')

    class Meta:
        db_table = 'foster_pets'


# 售宠
class SellPet(models.Model):
    state_choice = (
        ('1', '未上架'),
        ('2', '在售'),
        ('3', '已售')
    )
    sex_choice = (
        ('1', '雄性'),
        ('2', '雌性')
    )
    sell_id = models.CharField(max_length=30, verbose_name='宠物的商品ID', null=True)
    sell_name = models.CharField(max_length=30, verbose_name='出售宠物的名字', null=True)
    species = models.CharField(max_length=100, verbose_name='品种', null=True)
    catagory = models.CharField(max_length=10, verbose_name='种类', null=True)
    age = models.IntegerField(verbose_name='年龄', null=True)
    sex = models.CharField(max_length=20, verbose_name='性别', null=True)
    picture = models.URLField(verbose_name='存放图片地址', blank=True)
    quantity = models.IntegerField(verbose_name='在店数量', null=True)
    price = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='价格')
    create_time = models.DateTimeField(auto_now_add=True, null=True, verbose_name='上架时间')
    end_time = models.DateTimeField(null=True, verbose_name='预约下架时间')
    status = models.CharField(max_length=20, choices=state_choice, verbose_name='在店状态')
    description = models.CharField(max_length=200, verbose_name='简介')

    class Meta:
        db_table = 'sell_pets'


# 商店物品信息
class ShopGoods(models.Model):
    state_choice = (
        ('1', '未上架'),
        ('2', '在售'),
        ('3', '已售')
    )
    shopgoods_id = models.CharField(max_length=30, verbose_name='商品编号ID', null=True)
    shopgoods_name = models.CharField(max_length=30, verbose_name='商品名称', null=True)
    shopgoods_kind = models.CharField(max_length=30, verbose_name='商品品种', null=True)
    shopgoods_catagory = models.CharField(max_length=30, verbose_name='商品种类', null=True)
    picture = models.URLField(verbose_name='存放图片地址', blank=True)
    quantity = models.IntegerField(verbose_name='在店数量', null=True)
    price = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='价格')
    create_time = models.DateTimeField(auto_now_add=True, null=True, verbose_name='上架时间')
    end_time = models.DateTimeField(null=True, verbose_name='下架时间')
    status = models.CharField(max_length=20, choices=state_choice, verbose_name='在店状态')
    description = models.CharField(max_length=200, verbose_name='简介')

    class Meta:
        db_table = 'shop_goods'
